#!/bin/bash

echo "start building"

if [ "$1" ];then
    echo "命令传参";
    tag="$1";
else
    echo "没有参数";
    tag=$(date "+%Y%m%d%H%M")
fi

echo "tag=$tag"
if [ ! "$tag" ];then
    echo "tag is empty"
    exit 0
fi
echo "把项目copy到当前www目录下"
rsync -ar --exclude={*.git*,.idea,.vscode,composer*,*.log,runtime/*}  ../hemabackend/ ./www

echo "php docker build..."
docker build . -f phpfpm.Dockerfile -t registry.cn-hangzhou.aliyuncs.com/zxywyy/zhao-fpm:"$tag"

echo "php docker pushing"
docker push registry.cn-hangzhou.aliyuncs.com/zxywyy/zhao-fpm:"$tag"

echo "nginx docker build..."
docker build . -f nginx.Dockerfile -t registry.cn-hangzhou.aliyuncs.com/zxywyy/nginx:"$tag"

echo "nginx docker pushing"
docker push registry.cn-hangzhou.aliyuncs.com/zxywyy/nginx:"$tag"


echo "all is ok"
